import request from '@/utils/request'
import download from "@/utils/download";
import {IAesKey, IUser} from "@/iwb/IUser";

/** 调用统一鉴权服务 */
export function register (data: any) {
  return request({
    url: '/wb/auth/register',
    method: 'post',
    data
  })
}

/**
 * 修改密码
 * @param data
 */
export function changePassword(data: any) {
  return request({
    url: '/wb/auth/change/password',
    method: 'post',
    data
  })
}

/**
 * 获取RSA公钥
 */
export function publicKey() {
  return request({
    url: '/wb/auth/publicKey',
    method: 'get'
  })
}

export function login (data: any) {
  return request({
    url: '/wb/auth/login',
    method: 'post',
    data
  })
}

export function verifyCode() {
  return download({
    url: '/wb/auth/code',
    method: 'get'
  })
}

export function logout () {
  return request({
    url: '/wb/auth/logout',
    method: 'get'
  })
}

/**
 * 获取用户注册邀请码
 * @param phone
 */
export function createCode(phone: string) {
  return request({
    url: '/wb/user/createCode',
    method: 'get',
    params: {phone}
  })
}

/**
 * 批量创建用户ID供使用
 * @param begin
 * @param end
 */
export function createUserId(begin: number, end: number) {
  return request({
    url: '/wb/user/createUserId',
    method: 'get',
    params: {begin, end}
  })
}

/** 调用wb后端服务 */
export function getInfo (userId: number) {
  return request({
    url: '/wb/user/info',
    method: 'get',
    params: { userId }
  })
}

export function updateInfo (data: any) {
  return request({
    url: '/wb/user/info',
    method: 'post',
    data
  })
}

export function bindUserDept(data: any) {
  return request({
    url: '/wb/user/bind',
    method: 'post',
    data
  })
}

export function queryUserByDeptId(pageIndex: number, pageSize: number, deptId: number) {
  return request({
    url: '/wb/user/id',
    method: 'get',
    params: {pageIndex, pageSize, id: deptId}
  })
}

/**
 * 设置用户是否是审批人
 * @param data
 */
export function setUserApprover(data: any) {
  return request({
    url: '/wb/user/approver',
    method: 'put',
    data
  })
}

/**
 * 分页查询用户信息
 * @param pageIndex
 * @param pageSize
 */
export function queryUser(pageIndex: number, pageSize: number) {
  return request({
    url: '/wb/user/query',
    method: 'get',
    params: { pageIndex, pageSize }
  })
}

/**
 * 更新用户信息
 * @param user
 */
export function updateUser(user: IUser) {
  return request({
    url: '/wb/user/info',
    method: 'put',
    data: user
  })
}

/**
 * 同步最新key到服务器
 * @param aesKey
 */
export function syncAesKey(aesKey: IAesKey) {
  return request({
    url: '/wb/auth/sync/key',
    method: 'post',
    data: aesKey
  })
}

export function getUserInfoByU(user: IUser, isOr: boolean) {
  return request({
    url: '/wb/user/query/'+isOr,
    method: 'post',
    data: user
  })
}